/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
	"fmt"

	"github.com/spf13/cobra"

	"internal_training_be/jwt"
)

// generateTokenCmd represents the generateToken command
var generateTokenCmd = &cobra.Command{
	Use:   "generateToken",
	Short: "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {
		
		// 生成员工token
		employeeToken, err := jwt.NewServiceForEmployee().GenerateToken(args[0]);
		if err != nil {
			fmt.Errorf("failed to generate employee token: %v", err.Error())
			return
		}

		if args[1] == "admin" {
			// 生成管理员token
			adminToken, err := jwt.NewServiceForAdmin().GenerateToken(args[0]);
			if err != nil {
				fmt.Errorf("failed to generate admin token: %v", err.Error())
				return
			}
			fmt.Println("admin token: ", adminToken)
			return
		}

		fmt.Println("employee token: ", employeeToken)
	},
}

func init() {
	rootCmd.AddCommand(generateTokenCmd)

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// generateTokenCmd.PersistentFlags().String("foo", "", "A help for foo")

	// Cobra supports local flags which will only run when this command
	// is called directly, e.g.:
	// generateTokenCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
